// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from '@/App'
import router from '@/router'
import store from '@/store'
import { LoadingPlugin, AlertPlugin, ConfirmPlugin, ToastPlugin } from 'vux'
import '@/config/font-rem.js'
import { vmfilter, vmdata } from '@/vmixin/vmixin'
import { validate } from '@/middleware/validateInfo'
Vue.use(LoadingPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(ToastPlugin)
Vue.config.productionTip = false
Vue.mixin(vmfilter)
Vue.mixin(vmdata)
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  validate().then(valResult => {
    if (!valResult && to.path !== '/login') {
      next('/login')
    } else {
      next()
    }
  })
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
